package cn.chinaflame.pagodas.service;

import cn.chinaflame.pagodas.enums.CodeEnum;
import cn.chinaflame.pagodas.utils.ParamPreconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * 生成主键service
 *
 * @author created by boming
 * @date 2018年1月5日 下午12:59:15
 */
@Service
public class IdGeneratorService {


    private static final Logger log = LoggerFactory.getLogger(IdGeneratorService.class);


    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 根据表名获得主键
     *
     * @param tableName
     * @return
     */
    public String generateIdByTableName(String tabName) {
        log.info("获取表主键tabName:{}", tabName);
        String sqlStr = "select nextid('" + tabName + "') from DUAL";
        String idStr = null;
        idStr = jdbcTemplate.queryForObject(sqlStr, java.lang.String.class);
        ParamPreconditions.checkNotNull(idStr, CodeEnum.FAIL.getCode(), "获取主键失败");
        return idStr;
    }

    /**
     * 根据项目表主键
     *
     * @return
     */
    public String generateItemId() {
        return generateIdByTableName("yw_item");
    }

    /**
     * 生成商品区域id
     *
     * @return
     */
    public String generateProductAreaId() {
        return generateIdByTableName("yw_product_area");
    }

    /**
     * 生成商品位置id
     *
     * @return
     */
    public String generateProductPositionId() {
        return generateIdByTableName("pa_product_position");
    }

    /**
     * 生成会员id
     *
     * @return
     */
    public String generateMemberId() {
        return generateIdByTableName("pa_member");
    }

    /**
     * 生成会员id
     *
     * @return
     */
    public String generateAgentId() {
        return generateIdByTableName("pa_agent");
    }

    /**
     * @return
     */
    public String generateBlessId() {
        return generateIdByTableName("pa_bless");
    }

    /**
     * @return
     */
    public String generateInvitationId() {
        return generateIdByTableName("pa_invitation");
    }

    /**
     * 墓地套餐表id
     */

    public String generateWoPlanId() {
        return generateIdByTableName("wo_plan");
    }

    /**
     * 祭拜会员与逝者绑定表
     */
    public String generateWoWorshipId() {
        return generateIdByTableName("wo_worship");
    }

    /**
     * 祭拜会员表
     *
     * @return
     */
    public String generateWoMemberId() {
        return generateIdByTableName("wo_member");
    }

    /**
     * 祭拜订单详情表
     */
    public String generateWoOrderItemId() {
        return generateIdByTableName("wo_orderitem");
    }

    /**
     * 生成订单id
     *
     * @return
     */
    public String generatePaOrderId() {
        return generateIdByTableName("pa_order");
    }

    /**
     * 生成订单id
     *
     * @return
     */
    public String generateWoOrderitemId() {
        return generateIdByTableName("pa_orderitem");
    }
    /*new_edition 生成行列位置id*/

    /**
     * 生成订单id
     *
     * @return
     */
    public String generatePaProductPointId() {
        return generateIdByTableName("pa_product_point");
    }

    /**
     * 生成订单id
     *
     * @return
     */
    public String generatePaOrderitemId() {
        return generateIdByTableName("pa_orderitem");
    }
    /**
     * 生成PaBalmOrderId
     */
    public String generatePaBalmOrderId(){
    	return generateIdByTableName("pa_balm_order");
    }
}












